﻿/*=================================================================
* 版权信息：Copyright (C) 2005-2011 捷点科技 All Rights Reserved.
* 文件名称：CNVP_ProTypeRefBranks.cs
* 创建标识：曾乃强 15158756652 2011-04-01 10:04:13
* 修改标识：
* 功能描述：
===================================================================*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using CNVP.Framework.Helper;
using CNVP.Config;

namespace CNVP.JShop.DAL
{
    /// <summary>
    /// 对*CNVP_ProTypeRefBranks*操作数据库(针对SQL Server)的实现
    /// </summary>
    public class CNVP_ProTypeRefBranks
    {
       private string Prefix = DBConfig.Prefix;
        #region DAL
        public int Insert(Model.CNVP_ProTypeRefBranks obj)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("insert into  " + Prefix + "ProTypeRefBranks ([ProductTypeID],[BranksIDS])");
            sql.Append("values(@ProductTypeID,@BranksIDS)");
            
            SqlParameter[] pra = {
                            new SqlParameter("@ProductTypeID",obj.ProductTypeID),
							new SqlParameter("@BranksIDS",obj.BranksIDS)
                                 };
            return DbHelper.ExecuteNonQuery(sql.ToString(), pra);
        }

        public int Update(Model.CNVP_ProTypeRefBranks obj)
        {
             StringBuilder sql = new StringBuilder();
             sql.Append("update " + Prefix + "ProTypeRefBranks set [BranksIDS] = @BranksIDS where [ProductTypeID] = @ProductTypeID");

            SqlParameter[] pra = { 
							new SqlParameter("@ProductTypeID",obj.ProductTypeID),
							new SqlParameter("@BranksIDS",obj.BranksIDS)
                                };
             return DbHelper.ExecuteNonQuery(sql.ToString(),pra);
        }

        public int Delete(Model.CNVP_ProTypeRefBranks obj)
        {
           StringBuilder sql = new StringBuilder();
           sql.Append("delete from " + Prefix + "ProTypeRefBranks where [ProductTypeID] = @ProductTypeID");
           SqlParameter[] pra = {
                                new SqlParameter("@ProductTypeID",obj.ProductTypeID)
						
                                };
           return DbHelper.ExecuteNonQuery(sql.ToString(),pra);
        }

        public List<Model.CNVP_ProTypeRefBranks> LoadAll()
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select [ID],[ProductTypeID],[BranksIDS] from " + Prefix + "ProTypeRefBranks");
            DataTable DT = DbHelper.ExecuteTable(sql.ToString());
            List<Model.CNVP_ProTypeRefBranks> list=new List<Model.CNVP_ProTypeRefBranks>();
            if (DT != null && DT.Rows.Count > 0)
            {
                foreach (DataRow dr in DT.Rows)
                {
                    Model.CNVP_ProTypeRefBranks cnvp_protyperefbranks = new Model.CNVP_ProTypeRefBranks();
                    cnvp_protyperefbranks.ID = dr["ID"] is DBNull ? 0 : (int)dr["ID"];
                    cnvp_protyperefbranks.ProductTypeID = dr["ProductTypeID"] is DBNull ? 0 : (int)dr["ProductTypeID"];
                    cnvp_protyperefbranks.BranksIDS = dr["BranksIDS"] is DBNull ? String.Empty : (string)dr["BranksIDS"];
                    list.Add(cnvp_protyperefbranks);
                }
            }
            return list;

        }

        public Model.CNVP_ProTypeRefBranks LoadById(int ID)
        {
            
            StringBuilder sql = new StringBuilder();
            sql.Append("select [ProductTypeID],[BranksIDS] from " + Prefix + "ProTypeRefBranks");
            sql.Append(" where [ID] = @ID");
            SqlParameter[] pra = {
                                 new SqlParameter("@ID",ID)
						
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(),pra);
            Model.CNVP_ProTypeRefBranks cnvp_protyperefbranks = new Model.CNVP_ProTypeRefBranks();
            if (DT != null && DT.Rows.Count > 0)
            {
                DataRow dr = DT.Rows[0];
                cnvp_protyperefbranks.ProductTypeID = dr["ProductTypeID"] is DBNull ? 0 : (int)dr["ProductTypeID"];
                cnvp_protyperefbranks.BranksIDS = dr["BranksIDS"] is DBNull ? String.Empty : (string)dr["BranksIDS"];
            } 
            return cnvp_protyperefbranks;
        }

        #endregion

        public Model.CNVP_ProTypeRefBranks LoadByProductTypeID(int ProductTypeID)
        {

            StringBuilder sql = new StringBuilder();
            sql.Append("select [ID],[BranksIDS] from " + Prefix + "ProTypeRefBranks");
            sql.Append(" where [ProductTypeID] = @ProductTypeID");
            SqlParameter[] pra = {
                                 new SqlParameter("@ProductTypeID",ProductTypeID)
						
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(), pra); 
            Model.CNVP_ProTypeRefBranks cnvp_protyperefbranks = new Model.CNVP_ProTypeRefBranks();
            if (DT != null && DT.Rows.Count > 0)
            {
                DataRow dr = DT.Rows[0];
                cnvp_protyperefbranks.ProductTypeID = dr["ID"] is DBNull ? 0 : (int)dr["ID"];
                cnvp_protyperefbranks.BranksIDS = dr["BranksIDS"] is DBNull ? String.Empty : (string)dr["BranksIDS"];
            }
            return cnvp_protyperefbranks;
        }

    }
}

